<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module-imgfile.html" />
<link rel="parent" href="sgi.html" />
<link rel="next" href="sunos.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>34.12 jpeg -- Read and write JPEG files</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="34.11 imgfile  "
  href="module-imgfile.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="34. sgi IRIX Specific"
  href="sgi.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="35. sunos Specific Services"
  href="sunos.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-imgfile.html">34.11 imgfile  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="sgi.html">34. SGI IRIX Specific</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="sunos.html">35. SunOS Specific Services</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION00361200000000000000000">
34.12 <tt class="module">jpeg</tt> --
         Read and write JPEG files</a>
</h1>

<p>
<a name="module-jpeg"></a>  
<p class="availability">Availability: <span
 class="platform">IRIX</span>.</p>

<p>
The module <tt class="module">jpeg</tt> provides access to the jpeg compressor and
decompressor written by the Independent JPEG Group
<a id='l2h-5729' xml:id='l2h-5729'></a>(IJG). JPEG is a standard for
compressing pictures; it is defined in ISO 10918.  For details on JPEG
or the Independent JPEG Group software refer to the JPEG standard or
the documentation provided with the software.

<p>
A portable interface to JPEG image files is available with the Python
Imaging Library (PIL) by Fredrik Lundh.  Information on PIL is
available at <a class="url" href="http://www.pythonware.com/products/pil/">http://www.pythonware.com/products/pil/</a>.
<a id='l2h-5730' xml:id='l2h-5730'></a>

<p>
The <tt class="module">jpeg</tt> module defines an exception and some functions.

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-5725' xml:id='l2h-5725' class="exception">error</tt></b></dt>
<dd>
Exception raised by <tt class="function">compress()</tt> and <tt class="function">decompress()</tt>
in case of errors.
</dd></dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5726' xml:id='l2h-5726' class="function">compress</tt></b>(</nobr></td>
  <td><var>data, w, h, b</var>)</td></tr></table></dt>
<dd>
Treat data as a pixmap of width <var>w</var> and height <var>h</var>, with
<var>b</var> bytes per pixel.  The data is in SGI GL order, so the first
pixel is in the lower-left corner. This means that <tt class="function">gl.lrectread()</tt>
return data can immediately be passed to <tt class="function">compress()</tt>.
Currently only 1 byte and 4 byte pixels are allowed, the former being
treated as greyscale and the latter as RGB color.
<tt class="function">compress()</tt> returns a string that contains the compressed
picture, in JFIF<a id='l2h-5731' xml:id='l2h-5731'></a> format.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5727' xml:id='l2h-5727' class="function">decompress</tt></b>(</nobr></td>
  <td><var>data</var>)</td></tr></table></dt>
<dd>
Data is a string containing a picture in JFIF<a id='l2h-5732' xml:id='l2h-5732'></a> format. It
returns a tuple <code>(<var>data</var>, <var>width</var>, <var>height</var>,
<var>bytesperpixel</var>)</code>.  Again, the data is suitable to pass to
<tt class="function">gl.lrectwrite()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5728' xml:id='l2h-5728' class="function">setoption</tt></b>(</nobr></td>
  <td><var>name, value</var>)</td></tr></table></dt>
<dd>
Set various options.  Subsequent <tt class="function">compress()</tt> and
<tt class="function">decompress()</tt> calls will use these options.  The following
options are available:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="left"  >Option</th>
      <th class="left"  >Effect</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="left"   valign="baseline"><code>'forcegray'</code></td>
        <td class="left"  >Force output to be grayscale, even if input is RGB.</td></tr>
    <tr><td class="left"   valign="baseline"><code>'quality'</code></td>
        <td class="left"  >Set the quality of the compressed image to a value between
    <code>0</code> and <code>100</code> (default is <code>75</code>).  This only affects
    compression.</td></tr>
    <tr><td class="left"   valign="baseline"><code>'optimize'</code></td>
        <td class="left"  >Perform Huffman table optimization.  Takes longer, but results in
    smaller compressed image.  This only affects compression.</td></tr>
    <tr><td class="left"   valign="baseline"><code>'smooth'</code></td>
        <td class="left"  >Perform inter-block smoothing on uncompressed image.  Only useful
    for low-quality images.  This only affects decompression.</td></tr></tbody>
</table></div>
</dl>

<p>
<div class="seealso">
  <p class="heading">See Also:</p>

  <dl compact="compact" class="seetitle">
    <dt><em class="citetitle"
        >JPEG Still Image Data Compression Standard</em></dt>
    <dd>The 
            canonical reference for the JPEG image format, by
            Pennebaker and Mitchell.</dd>
  </dl>

<p>
<dl compact="compact" class="seetitle">
    <dt><em class="citetitle"><a href="http://www.w3.org/Graphics/JPEG/itu-t81.pdf"
        >Information
            Technology - Digital Compression and Coding of
            Continuous-tone Still Images - Requirements and
            Guidelines</a></em></dt>
    <dd>The ISO standard for JPEG is also published as
            ITU T.81.  This is available online in PDF form.</dd>
  </dl>
</div>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="34.11 imgfile  "
  href="module-imgfile.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="34. sgi IRIX Specific"
  href="sgi.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="35. sunos Specific Services"
  href="sunos.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-imgfile.html">34.11 imgfile  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="sgi.html">34. SGI IRIX Specific</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="sunos.html">35. SunOS Specific Services</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
